package com.jsnu.xiaochi.service;

import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
public class PermService {

    /**
     * 模拟根据用户id查询返回用户的所有权限，实际查询语句参考：
     * SELECT p.pval FROM perm p, role_perm rp, user_role ur
     * WHERE p.pid = rp.perm_id AND ur.role_id = rp.role_id
     * AND ur.user_id = #{userId}
     * @param username
     * @return
     */
    public Set<String> getPermsByUsername(String username){
        Set<String> perms = new HashSet<>();

        if("admin".equals(username)){
            //小吃审核权限
            perms.add("food:pass");
            //分类的增删改
            perms.add("category:insert");
            perms.add("category:delete");
            perms.add("category:update");
            //小吃的增删改
            perms.add("food:insert");
            perms.add("food:delete");
            perms.add("food:update");

        }else{
            //小吃的申请
            perms.add("food:insert");

            //用户资料的编辑
            perms.add("user:update");
        }
        return perms;
    }

}
